package com.bootdo.analyze.service.impl;

import com.bootdo.analyze.dao.GoodsSellAIDao;
import com.bootdo.analyze.domain.GoodsSellAIDO;
import com.bootdo.analyze.service.GoodsSellAIService;
import com.bootdo.analyze.util.Dto;
import com.bootdo.analyze.util.DtoUtil;
import com.bootdo.analyze.util.WeiDuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class GoodsSellAIServiceImpl implements GoodsSellAIService {
    @Autowired
    private GoodsSellAIDao goodsSellAIDao;

    @Override
    public List<GoodsSellAIDO> list(Map<String, Object> map) {
        List<GoodsSellAIDO> goodsSellAIDOList = goodsSellAIDao.list(map);
        for (GoodsSellAIDO goodsSellAIDO:goodsSellAIDOList){
            int id = goodsSellAIDO.getId();
            String str_salescount=goodsSellAIDao.getSalescount(id);
            if (str_salescount==null || str_salescount==""){
                str_salescount="0";
            }
            goodsSellAIDO.setSalescount(Integer.parseInt(str_salescount));
            goodsSellAIDO.setSalesbase((goodsSellAIDao.getSalesbase(id)/3));
            Double salespercentage=(double)((goodsSellAIDO.getSalescount())*100/ (goodsSellAIDO.getSalesbase()));
            goodsSellAIDO.setSalespercentage(salespercentage);
            goodsSellAIDO.setTotalPrices(goodsSellAIDao.getTotalPrices(id));

            goodsSellAIDO.setWeiDuUtilList(goodsSellAIDao.getGoodsInfo(id));

        }
        return goodsSellAIDOList;
    }

    @Override
    public int count(Map<String, Object> map) {
        return goodsSellAIDao.count(map);
    }

    @Override
    public List<GoodsSellAIDO> getGoodsFluctuate(Map<String,Object> map) {
        List<GoodsSellAIDO> goodsSellAIDOList = goodsSellAIDao.getGoodsFluctuate(map);
        System.out.println("--------------------ddd----"+goodsSellAIDOList.size());
        for (GoodsSellAIDO goodsSellAIDO:goodsSellAIDOList){
            int id = goodsSellAIDO.getId();
            String str_salescount=goodsSellAIDao.getSalescount(id);
            if (str_salescount==null || str_salescount==""){
                str_salescount="0";
            }
            goodsSellAIDO.setSalescount(Integer.parseInt(str_salescount));

            goodsSellAIDO.setTotalPrices(goodsSellAIDao.getTotalPrices(id));



        }
        return goodsSellAIDOList;


    }


    public List<Dto> getGoodsFluctuate1(Map<String,Object> map) {
        List<Dto> dtoList = new ArrayList<Dto>();

        List<GoodsSellAIDO> goodsSellAIDOList = goodsSellAIDao.list(map);
        for (GoodsSellAIDO goodsSellAIDO:goodsSellAIDOList){
            int id = goodsSellAIDO.getId();
            String str_salescount=goodsSellAIDao.getSalescount(id);
            if (str_salescount==null || str_salescount==""){
                str_salescount="0";
            }
            goodsSellAIDO.setSalescount(Integer.parseInt(str_salescount));
            goodsSellAIDO.setSalesbase((goodsSellAIDao.getSalesbase(id)/3));
            Double salespercentage=(double)((goodsSellAIDO.getSalescount())*100/ (goodsSellAIDO.getSalesbase()));
            goodsSellAIDO.setSalespercentage(salespercentage);
            goodsSellAIDO.setTotalPrices(goodsSellAIDao.getTotalPrices(id));
            List<WeiDuUtil> weiDuUtilList = goodsSellAIDao.getGoodsInfo(id);
            for (WeiDuUtil weiDuUtil :weiDuUtilList){
                System.out.println("----------------------"+weiDuUtil.getCountWD());
            }
            /*for (int i = 0;i<weiDuUtilList.size();i++){
                mapResult.put("countWD"+i,weiDuUtilList.get(i).getCountWD());
                mapResult.put("pricesWD"+i,weiDuUtilList.get(i).getPricesWD());
                mapResult.put("goodsSellAIDO"+i,goodsSellAIDO);
            }*/
            Dto dto = DtoUtil.returnSuccess(goodsSellAIDO,weiDuUtilList);
            dtoList.add(dto);
        }
        return dtoList;
    }

    @Override
    public List<GoodsSellAIDO> getStockFluctuate(Map<String, Object> map) {
        List<GoodsSellAIDO> goodsSellAIDOList = goodsSellAIDao.getStockFluctuate(map);
        for (GoodsSellAIDO goodsSellAIDO:goodsSellAIDOList){
            int id = goodsSellAIDO.getId();
            String str_salescount=goodsSellAIDao.getStockcount(id);
            if (str_salescount==null || str_salescount==""){
                str_salescount="0";
            }
            goodsSellAIDO.setSalescount(Integer.parseInt(str_salescount));

            goodsSellAIDO.setTotalPrices(goodsSellAIDao.getStockTotalPrices(id));

        }
        return goodsSellAIDOList;
    }

    @Override
    public List<GoodsSellAIDO> getInventoryBacklog(Map<String, Object> map) {
        return goodsSellAIDao.getInventoryBacklog(map);
    }

    @Override
    public List<GoodsSellAIDO> getInventoryTurnover(Map<String, Object> map) {
        return goodsSellAIDao.getInventoryTurnover(map);
    }

    @Override
    public List<WeiDuUtil> getGoodsInfo(int id) {
        return goodsSellAIDao.getGoodsInfo(id);
    }
}
